@extends('layouts.app')
@section('title',($address->id ? '修改' : '新增').'收货地址')

@section('content')
   <div class="row">
       <div class="col-md-10 offset-md-1">
           <div class="card">
               <div class="card-header">
                   {{$address->id ? '修改' : '新增'}}收货地址
               </div>
               <div class="card-body">
                   @if(count($errors) > 0)
                       <div class="alert alert-danger">
                           <ul>
                               @foreach($errors->all() as $error)
                               <li>{{$error}}</li>
                               @endforeach
                           </ul>
                       </div>
                   @endif
                 <user-addresses-create-and-edit inline-template>
                     @if($address->id)
                         <form action="{{route('user_addresses.update',['user_address'=>$address->id])}}" method="post">
                             @method('put')
                     @else
                         <form action="{{route('user_addresses.store')}}" method="post">
                     @endif

                       @csrf
                       <select-district
                           :init-value="{{ json_encode([old('province', $address->province), old('city', $address->city), old('district', $address->district)]) }}"
                           @change="onDistrictChanged"
                           inline-template>
                       <div class="form-group row">
                           <label class="col-sm-2 col-form-label">省市区:</label>
                           <div class="col-sm-3">
                               <select class="form-control" v-model="provinceId">
                                   <option value="">选择省</option>
                                   <option v-for="(name,id) in provinces" :value="id">@{{ name }}</option>
                               </select>
                           </div>
                           <div class="col-sm-3">
                               <select class="form-control" v-model="cityId">
                                   <option value="">选择市</option>
                                   <option v-for="(name,id) in cities" :value="id">@{{ name }}</option>
                               </select>
                           </div>
                           <div class="col-sm-3">
                               <select class="form-control" v-model="districtId">
                                   <option value="">选择区</option>
                                   <option v-for="(name,id) in districts" :value="id">@{{ name }}</option>
                               </select>
                           </div>
                       </div>
                      </select-district>
                       <input type="hidden" name="province" v-model="province">
                       <input type="hidden" name="city" v-model="city">
                       <input type="hidden" name="district" v-model="district">
                       <div class="form-group row">
                           <label class="col-sm-2 col-form-label">详细地址:</label>
                           <div class="col-sm-9">
                               <input type="text" class="form-control" name="address" value="{{old('address',$address->address)}}">
                           </div>
                       </div>
                       <div class="form-group row">
                           <label class="col-sm-2 col-form-label">邮编:</label>
                           <div class="col-sm-9">
                               <input type="text" class="form-control" name="zip" value="{{old('zip',$address->zip)}}">
                           </div>
                       </div>
                       <div class="form-group row">
                           <label class="col-sm-2 col-form-label">姓名:</label>
                           <div class="col-sm-9">
                               <input type="text" class="form-control" name="contact_name" value="{{old('contact_name',$address->contact_name)}}">
                           </div>
                       </div>
                       <div class="form-group row">
                           <label class="col-sm-2 col-form-label">电话:</label>
                           <div class="col-sm-9">
                               <input type="text" class="form-control" name="contact_phone" value="{{old('contact_phone',$address->contact_phone)}}">
                           </div>
                       </div>
                       <div class="d-flex justify-content-center">
                           <button class="btn btn-primary">提交</button>
                       </div>
                   </form>
                 </user-addresses-create-and-edit>
               </div>
           </div>
       </div>
   </div>
@stop
